package com.lianzhihui.romeex.mvp.presenter;

import android.content.Context;


import com.lianzhihui.romeex.bean.user.CountryCode;
import com.lianzhihui.romeex.bean.user.WalletInfo;
import com.lianzhihui.romeex.mvp.model.LoginModelImp;
import com.lianzhihui.romeex.mvp.model.LoginModelInterface;
import com.lianzhihui.romeex.mvp.view.LoginView;

import java.util.List;

//逻辑实现
public class LoginPresnterImp implements LoginModelInterface {

    private final LoginView loginView;
    private final LoginModelImp loginModelImp;

    public LoginPresnterImp(Context context, LoginView loginView) {
        this.loginView = loginView;
        loginModelImp = new LoginModelImp(context, this);
    }

    public void postCreateWallet() {
        loginModelImp.createWallet();
    }

    public void postImportWallet() {
        loginModelImp.importWallet();
    }

    public void setWalletInfo(WalletInfo object) {
        loginModelImp.setWalletInfo(object);
    }

    public void syncWalletInfo(WalletInfo walletInfo) {
        loginModelImp.syncWalletInfo(walletInfo);
    }

    public void getCountryCodeList() {
        loginModelImp.getCountryCodeList();
    }

    public void getPhoneCode(String phoneNumber, String countryCode) {
        loginModelImp.getPhoneCode(phoneNumber, countryCode);
    }

    public void doSyncPhoneCode(String phone, String verCode, String areaCode) {
        loginModelImp.syncPhoneCode(phone, verCode, areaCode);
    }

    @Override
    public void onLoadCreateSuccess(WalletInfo data) {
        loginView.setAccountData(data);
    }

    @Override
    public void onLoadImportSuccess(WalletInfo data) {
        loginView.setImportData(data);
    }

    @Override
    public void onGetPhoneCodeSuccess(String s) {
        loginView.setPhoneCodeData(s);
    }

    @Override
    public void onSyncPhoneCodeSuccess(String s) {
        loginView.setSyncPhoneCodeData(s);
    }

    @Override
    public void onSyncWalletSuccess() {
        loginView.setSyncData(true, 200);
    }

    @Override
    public void onSetWalletSuccess(WalletInfo data) {
        loginView.setWalletData(data);
    }

    @Override
    public void onLoadReaginSuccess(List<CountryCode> data) {
        loginView.setCountryCodeData(data);
    }

    @Override
    public void onSyncWalletFailed(int code) {
        loginView.setSyncData(false, code);
    }

    @Override
    public void onFailure() {
        loginView.setFailure();
    }
}
